
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>3、Spring的依赖注入 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>3、Spring的依赖注入 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Spring框架中依赖注入（DI）的核心目的是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">依赖注入（DI）的主要目的是解耦。通过依赖注入，Spring可以将一个对象所需要的依赖关系注入给它，而不需要对象自己去管理依赖。</div>
          </div>
          <div class="card-source">来源: 1. 依赖注入概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Spring框架提供了哪三种主要的依赖注入方式？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring提供了三种主要的依赖注入方式：构造器注入、Setter注入和字段注入。</div>
          </div>
          <div class="card-source">来源: 1. 依赖注入概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Spring中，哪个接口是容器的根接口，负责Bean的实例化、管理和依赖注入？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">BeanFactory是Spring容器的根接口，它负责Bean的实例化、管理和依赖注入。</div>
          </div>
          <div class="card-source">来源: 2. Spring 的依赖注入核心接口</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">相比于其他注入方式，构造器注入最主要的优势是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">构造器注入的明显优势是强制依赖。在构造器注入中，所有依赖项都必须在Bean实例化时传入，从而避免了依赖项未注入的情况。</div>
          </div>
          <div class="card-source">来源: 4.2 构造器注入的优点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Setter注入方式的灵活性体现在哪里？它更适用于哪种场景？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Setter注入通常比构造器注入更灵活，因为它允许在Bean初始化之后再设置依赖。因此，它适用于可选的依赖项。</div>
          </div>
          <div class="card-source">来源: 5.2 Setter注入的优点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">字段注入方式虽然简洁，但存在什么缺点，导致它在某些场景下不被推荐使用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">字段注入没有强制依赖检查，也没有方法来管理初始化顺序。因此，它一般不推荐用于依赖较多的场景。</div>
          </div>
          <div class="card-source">来源: 6.2 字段注入的优点与缺点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Spring的“按名称自动装配”机制是如何工作的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">按名称自动装配会先根据字段名称查找对应的Bean，然后进行注入。如源码中所示，它会检查容器中是否存在与字段名相同的Bean。</div>
          </div>
          <div class="card-source">来源: 7.2 按名称自动装配</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Spring的Bean生命周期管理中，BeanPostProcessor接口扮演了什么角色？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">BeanPostProcessor是Spring提供的一种扩展机制，它允许开发者在Bean实例化后、初始化前和初始化后进行自定义操作，例如修改Bean的依赖注入行为或为其注入额外功能。</div>
          </div>
          <div class="card-source">来源: 8.1 BeanPostProcessor 的角色</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Spring中，主要由哪个类来处理@Autowired注解，以实现自动依赖注入？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Spring通过`AutowiredAnnotationBeanPostProcessor`来处理`@Autowired`注解，并在实例化Bean时自动注入其构造器、Setter方法或字段的依赖。</div>
          </div>
          <div class="card-source">来源: 4.1 构造器注入实现</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
